package stone;

import stone.ast.ArrayLiteral;
import stone.ast.ArrayRef;
import static stone.Parser.rule;


// elements:		expr { "," expr }
// primary:			( "[" [elements] "]" | "(" expr ")" | NUMBER | IDENTIFIER | STRING ) { posfix }
// postfix:			"(" [args] ")" | "[" expr "]"


public class ArrayParser extends FuncParser {
	
	Parser elements = rule(ArrayLiteral.class).ast(expr).repeat(rule().sep(",").ast(expr));
	
	public ArrayParser() {
		reserved.add("]");
		primary.insertChoice(rule().sep("[").maybe(elements).sep("]"));
		posfix.insertChoice(rule(ArrayRef.class).sep("[").ast(expr).sep("]"));
	}
	
}
